package exemploapplet;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferStrategy;
import javax.swing.JApplet;

public class Main extends JApplet implements Runnable
{
	int x;
	Canvas canvas;
	BufferStrategy bs;

	@Override
	public void init()
	{
		canvas = new Canvas();
		setIgnoreRepaint(true);
		this.add(canvas);
		Thread t = new Thread(this);
		t.start();
	}

	public void run()
	{
		canvas.createBufferStrategy(2);
		bs = canvas.getBufferStrategy();
		while (true)
		{
			Thread.yield();
			update();
			render();
		}
	}

	public void update()
	{
		if (++x > 255)
		{
			x = 0;
		}
	}

	public void render()
	{
		Graphics2D g = (Graphics2D) bs.getDrawGraphics();
		if (g != null)
		{
			g.setColor(new Color(x, x, x));
			g.fillRect(0, 0, getWidth(), getHeight());
			g.dispose();
		}
		bs.show();
	}
}
